/**
 * 
 */
package com.jzweb.zxing.controller;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.jzweb.zxing.util.QRCodeUtils;

/**
 * @author 030998
 *
 */
@Controller
@RequestMapping("/demo/")
public class ZxingController {

	@RequestMapping("/qrcode")
	public void qrcode(HttpServletRequest request, HttpServletResponse response) throws IOException {
		response.setContentType("image/jpg");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		
		OutputStream os = response.getOutputStream();
		String content = "askljdlkjasd";
		
		BitMatrix bitMatrix = QRCodeUtils.createCode(content);
		MatrixToImageWriter.writeToStream(bitMatrix, "jpg", os);
	}
}
